package marlon.smsbatcheditor.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 
 * @author marlonyao<yaolei135@gmail.com>
 */
public class Rule {
	private long id = -1;
	private String name;
	
	private List<RuleCondition> conds = new ArrayList<RuleCondition>(1);
	private List<RuleAction> actions = new ArrayList<RuleAction>(1);
	
	public Rule(String name) {
		this.name = name;
	}
	
	public Rule(long id, String name) {
		this.id = id;
		this.name = name;
	}
	
	public long getId() {
		return id;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Iterator<RuleCondition> getConditions() {
		return conds.iterator();
	}
	
	public int getConditionCount() {
		return conds.size();
	}
	
	public void addCondition(RuleCondition cond) {
		conds.add(cond);
	}
	
	public RuleCondition getCondition(int index) {
		return conds.get(index);
	}
	
	public Iterator<RuleAction> getActions() {
		return actions.iterator();
	}
	
	public int getActionCount() {
		return actions.size();
	}
	
	public void addAction(RuleAction action) {
		actions.add(action);
	}
	
	public RuleAction getAction(int index) {
		return actions.get(index);
	}
	
	@Override
	public String toString() {
		return name;
	}
	
	public boolean equals(Object o) {
		if (o == this) return true;
		if (!(o instanceof Rule)) return false;
		Rule other = (Rule) o;
		return id == other.id && name.equals(other.name);
	}
	
	public int hashCode() {
		int result = 17;
		result ^= id;
		result ^= name.hashCode();
		return result;
	}
}
